package com.github.xaidanwang.data.upload.download.controller;

import com.github.xaidanwang.data.upload.download.cache.RedisDao;
import com.github.xaidanwang.response.CommonResult;
import com.github.xaidanwang.response.ConstantEnum;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author wang yi fei
 * @date 2020/4/6 15:09
 */
@RestController
@Slf4j
@RequestMapping("/room")
public class DouyinRedBackController {
	@Autowired
	private RedisDao redisDao;
	@ApiOperation(value = "上传有红包的房间号")
	@GetMapping(value = "/uploadRoom")
	public CommonResult uploadTaskRoom(String roomId){
		log.info("上传有红包的房间号:{}",roomId);
		if (StringUtils.isEmpty(roomId) || roomId.equals("undefined")){
			return CommonResult.buildWithData(ConstantEnum.GLOBAL_FAIL,"房间号不能为空!");
		}
		redisDao.addRoomIdlibList(roomId);
		return CommonResult.buildWithData(ConstantEnum.GLOBAL_SUCCESS,"上传成功!");
	}

	@ApiOperation(value = "直播间库循环获取直播间id")
	@GetMapping(value = "/getRoomId")
	public CommonResult getTaskRoomId(){
		// 获取下一个直播间房间号
		String roomId = redisDao.getRoomIdFromlibList();
		return CommonResult.buildWithData(ConstantEnum.GLOBAL_SUCCESS,roomId);
	}
}
